﻿@{
    ViewBag.Title = "动态";
}
<h3>动态列表</h3>
<div align="center">
    <hr />
    <table class="tb" style="padding-right:50px;">
        <tbody>
            <tr>
                <td>
                    <div class="search">
                        <a href="/manage/project">项目列表&gt;&gt; </a>
                        <span id="lblXMMC" style="color:Red;">@ViewBag.PName</span>
                    </div>
                </td>
                <td style="width:88px;">
                    <a href="/manage/news/edit?pid=@ViewBag.ID&pname=@ViewBag.PName">添加动态</a> 
                </td>
            </tr>
        </tbody>
    </table>
    <hr />
    <table class="tb" cellspacing="0" cellpadding="4" style="color:#333333;">
	    <tbody>
            <tr style="color:Black;background-color:#E2F4FE;font-weight:bold;">
			    <th scope="col">动态标题</th>
                <th scope="col">发布时间</th>
                <th scope="col">动态地址</th>
                <th scope="col">管理</th>
		    </tr>
        </tbody>
        <tbody id ="tablist">
        </tbody>
    </table>
    <hr />
    <!--page-->
    <input type="hidden" id ="pid" value="@ViewBag.ID" />
    <div class="pagehtml pagination" style="text-align: center; margin-top:5px;"></div>
</div>
<script src="http://qibu.net.cn/Style/public/plugins/json.dateHelper.js" type="text/javascript"></script>
@tour.szhome.common.CommPath.ScriptImport("public/plug-in/uploadify/jquery.uploadify-3.2.js")
<script type="text/javascript">
    var pageIndex = 1;
    var pageSize = 10;
    var shtml;
    $(function () {
        GetList(pageIndex);
    });

    //get list data
    function GetList(_pageIndex) {
        pageIndex = _pageIndex;
        $.ajax({
            url: "/news/get_news_list",
            type: "POST",
            dataType: "json",
            data: {
                page: pageIndex,
                pageSize: pageSize,
                projectId: $("#pid").val()
            },
            timeout: 30000,
            success: function (data) {
                if (data.list.length > 0) {
                    $(".pagehtml").show();
                    createHTML(data.list);
                    $(".pagehtml").pagination(data.recordCount, { load_callback: false, callback: pageselectCallback, current_page: data.page, items_per_page: data.pageSize, link_to: "#" });
                }
                else {
                    $(".pagehtml").hide();
                    $("#tablist").html("<tr><td colspan='4' style='color:red;'>没有数据！</td></tr>");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                dlg.Msg.Err(errorThrown);
            }
        });
    }

    // page call back function
    function pageselectCallback(page_index) {
        GetList(page_index);
    }

    //create html
    function createHTML(data) {
        var html = "";
        $(data).each(function (i, item) {
            var _tr = '<tr id=' + item.DTID + '  onmouseover="this.style.backgroundColor=\'#E2F4FE\'" onmouseout="this.style.backgroundColor=\'#ffffff\'" style="background-color: rgb(255, 255, 255);">'
              + '<td style="padding-left:20px; ">' + item.DTBT + '</td>'
              + '<td style="padding-left:20px; ">' + JsonDateHelper.getFormatDateTime(item.FBSJ, "{yyyy}-{m}-{d} {hh}:{mm}:{ss}") + '</td>'
              + '<td style="padding-left:20px; ">' + item.DTDZ + '</td>'
              + '<td align="center"><a href="/manage/news/edit/' + item.DTID + '?pid=@ViewBag.ID' + '&pname=@ViewBag.PName">编辑</a>\
                <a href="javascript:void(0);" onclick="del_news(' + item.DTID + ')">删除</a>';
              + '</tr>';
            html += _tr;
        });
        $("#tablist").html(html);
    }

    //delete
    function del_news(nid) {
        dlg.Confirm('提示', '确定要删除该项吗 ?', function () {
            $.getJSON("/news/json_delete", { nid: nid }, function (data) {
                if (data) {
                    dlg.Msg.Cor("操作成功");
                    setTimeout("$('#' + " + nid + ").remove();", 500);
                }
                else {
                    dlg.Msg.Err("操作失败");
                }
            });
        });
    }
</script>
